/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package graph;
import structures.*;


/**
 *
 * @author Gonzalo
 */
public class Nodes {
    public Set S;
    public boolean universe=false;
    public long size_universe=0;

    public Nodes(){
        S=new Set(100000);
    }

    public Nodes(Long s){
        S=new Set();
        S.add(s);
    }

    public boolean isUniverse(){
        return universe;
    }

    public void add(Long s){
        S.add(s);
    }
    public void remove(Long s){
        S.remove(s);
    }
    public boolean contains(long n){
        return S.contains(n);
    }

    public long count(){
        return S.size();
    }

    public void init(){
        S.init();
    }

    public void initSorter(){
        S.initSorter();
    }


    public boolean notNull(){
        return S.notNull();
    }

    public void next(){
        S.next();
    }

    public long getActual(){
        return S.getActual();
    }


    public Nodes interseccion(Nodes X){
        if(X.isUniverse())
            return this;
        else if(isUniverse())
            return X;
        else if(X.count()<count()){
            for(X.init();X.notNull();X.next()){
                if(!S.contains(X.getActual()))
                    X.remove(X.getActual());
            }
            return X;
        }else{
            for(init();notNull();next())
                if(!X.contains(getActual()))
                   remove(getActual());
            return this;
        }
    }


    public Nodes union(Nodes X){
        if(X.isUniverse())
            return X;
        else if(isUniverse())
            return this;
        else if(X.count()<count()){
            for(X.init();X.notNull();X.next())
                S.add(X.getActual());
            return this;
        }else{
            for(init();notNull();next())
                X.add(getActual());
            return X;
        }
    }


    public Nodes diferencia(Nodes X){
        if(X.isUniverse())
            return new Nodes();
        else if(isUniverse())
            return X.complemento();
        else if(X.count()<count()){
            for(X.init();X.notNull();X.next())
                S.remove(X.getActual());
            return this;
        }else{
            for(init();notNull();next()){
                if(X.contains(getActual()))
                    S.remove(getActual());
            }
            return this;
        }
    }

    public void diferenciaUnion(Nodes X){//a X le agrego Actual, a Actual le resto X
            for(init();notNull();next()){
                if(X.contains(getActual()))
                    S.remove(getActual());
                else
                    X.add(getActual());
            }
    }

    public Nodes complemento(){//FALTA
        return new Nodes(); 
    }
}
